package com.wdg.template.repository.impl;

import com.github.wenhao.jpa.PredicateBuilder;
import com.github.wenhao.jpa.Specifications;
import com.wdg.common.reponsitory.DataJpaBaseDao;
import com.wdg.template.entity.TemplateEntity;
import com.wdg.template.repository.TemplateRepositoryI;
import com.wdg.template.repository.jpa.TemplateJpaRepository;
import org.springframework.stereotype.Repository;
/**
 * 持久化层 DataJpaBaseDao中实现了UserRepositoryI 中的基本接口
 */
@Repository
public class TemplateRepositoryImpl extends DataJpaBaseDao<TemplateEntity,Long> implements TemplateRepositoryI {

    private TemplateJpaRepository templateJpaRepository;

    public TemplateRepositoryImpl(TemplateJpaRepository dataJpaRepository) {
        super(dataJpaRepository);
        templateJpaRepository = dataJpaRepository;
    }
    @Override
    public TemplateEntity findByPhoneNumber(String phoneNumber) {
        PredicateBuilder<TemplateEntity> builder = Specifications.and();

        builder.eq("phoneNumber",phoneNumber);
        builder.eq("deleted",Boolean.FALSE);
        return templateJpaRepository.findOne(builder.build()).orElse(null);
    }
}
